package domain

import (
	"dlist/common/result"
	"github.com/gin-gonic/gin"
	"net/http"
)

type ServerResult[T any] struct {
	Code string `json:"code"`
	Msg  string `json:"msg"`
	Data T      `json:"data"`
}

func Success[T any](c *gin.Context, data T) {
	c.JSON(http.StatusOK, ServerResult[T]{
		Code: result.SUCCESS.Code,
		Msg:  result.SUCCESS.Msg,
		Data: data,
	})
}

func Fail(c *gin.Context, code result.ResultCode) {
	c.JSON(http.StatusOK, ServerResult[any]{
		Code: code.Code,
		Msg:  code.Msg,
	})
}
